//
//  HamatonAboutViewController.swift
//  hamaton-app
//
//  Created by intyt on 2024/5/8.
//

import UIKit
import SnapKit
import SafariServices

class HamatonAboutViewController: HamatonBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = Theme.Color.Background.default
        navigationItem.title = "关于"
        let margTop: Float = 15
        let margRight: Float = -20
        let margLeft: Float = 20
        
        view.addSubview(MainLogoImg)
        view.addSubview(ZhihuiwantongLabel)
        view.addSubview(BanbenhaoLabel)
        // 访问官网
        view.addSubview(FangwenguanwangLabel)
        view.addSubview(FangwenguanwangButton)
        view.addSubview(FangwenguanwangRightImg)
        view.addSubview(lineView1)
        view.addSubview(lineView2)
        // 用户协议
        view.addSubview(YonghuxieyiLabel)
        view.addSubview(YonghuxieyiButton)
        view.addSubview(YonghuxieyiRightImg)
        view.addSubview(lineView3)
        // 隐私政策
        view.addSubview(YinsizhengceLabel)
        view.addSubview(YinsizhengceButton)
        view.addSubview(YinsizhengceRightImg)
        view.addSubview(lineView4)
        // 底部公司
        view.addSubview(BottomLabel)
        view.addSubview(BottomLeftImg)
        // logo
        MainLogoImg.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop*4)
            // x轴居中对齐
            make.centerX.equalToSuperview()
            make.width.equalTo(170)
            make.height.equalTo(180)
        }
        ZhihuiwantongLabel.snp.makeConstraints { make in
            make.top.equalTo(MainLogoImg.snp.bottom).offset(margTop)
            // x轴居中对齐
            make.centerX.equalToSuperview()
            make.width.equalTo(180)
            make.height.equalTo(40)
        }
        BanbenhaoLabel.snp.makeConstraints { make in
            make.top.equalTo(ZhihuiwantongLabel.snp.bottom).offset(0)
            // x轴居中对齐
            make.centerX.equalToSuperview()
            make.width.equalTo(180)
            make.height.equalTo(40)
        }
        // 访问官网
        FangwenguanwangLabel.snp.makeConstraints { make in
            make.top.equalTo(BanbenhaoLabel.snp.bottom).offset(margTop*3)
            make.left.equalToSuperview().offset(margLeft)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        FangwenguanwangRightImg.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(margRight)
            make.centerY.equalTo(FangwenguanwangLabel.snp.centerY)
            make.width.equalTo(8)
            make.height.equalTo(14)
        }
        FangwenguanwangButton.snp.makeConstraints { make in
            make.top.equalTo(BanbenhaoLabel.snp.bottom).offset(margTop*3)
            make.left.equalToSuperview().offset(0)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        lineView1.snp.makeConstraints { make in
            make.bottom.equalTo(FangwenguanwangButton.snp.top).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        lineView2.snp.makeConstraints { make in
            make.top.equalTo(FangwenguanwangButton.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        // 用户协议
        YonghuxieyiLabel.snp.makeConstraints { make in
            make.top.equalTo(lineView2.snp.bottom).offset(0)
            make.left.equalToSuperview().offset(margLeft)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        YonghuxieyiRightImg.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(margRight)
            make.centerY.equalTo(YonghuxieyiLabel.snp.centerY)
            make.width.equalTo(8)
            make.height.equalTo(14)
        }
        YonghuxieyiButton.snp.makeConstraints { make in
            make.top.equalTo(lineView2.snp.bottom).offset(0)
            make.left.equalToSuperview().offset(0)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        lineView3.snp.makeConstraints { make in
            make.top.equalTo(YonghuxieyiButton.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        // 隐私政策
        YinsizhengceLabel.snp.makeConstraints { make in
            make.top.equalTo(lineView3.snp.bottom).offset(0)
            make.left.equalToSuperview().offset(margLeft)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        YinsizhengceRightImg.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(margRight)
            make.centerY.equalTo(YinsizhengceLabel.snp.centerY)
            make.width.equalTo(8)
            make.height.equalTo(14)
        }
        YinsizhengceButton.snp.makeConstraints { make in
            make.top.equalTo(lineView3.snp.bottom).offset(0)
            make.left.equalToSuperview().offset(0)
            make.right.equalToSuperview().offset(0)
            make.height.equalTo(48)
        }
        lineView4.snp.makeConstraints { make in
            make.top.equalTo(YinsizhengceButton.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        // 底部公司
        BottomLabel.snp.makeConstraints { make in
            make.top.equalTo(lineView4.snp.bottom).offset(margTop*4)
            make.left.equalToSuperview().offset(0)
            make.right.equalToSuperview().offset(0)
            make.width.equalTo(200)
            make.height.equalTo(16)
        }
        BottomLeftImg.snp.makeConstraints { make in
            make.top.equalTo(lineView4.snp.bottom).offset(margTop*4)
            make.right.equalTo(BottomLabel.snp.left).offset(80)
            make.width.equalTo(16)
            make.height.equalTo(16)
        }
    }

    private lazy var MainLogoImg: UIImageView = {
        let view = UIImageView(image: UIImage(named: "main_logo"))
        return view
    }()
    
    private lazy var ZhihuiwantongLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "智汇万通"
        label.backgroundColor = .clear
        label.textAlignment = .center
        return label
    }()
    
    private lazy var BanbenhaoLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "版本号：1.0.0"
        label.backgroundColor = .clear
        label.textAlignment = .center
        return label
    }()
    
    // 访问官网
    private lazy var FangwenguanwangLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "访问官网"
        label.textAlignment = .left
        return label
    }()
    private lazy var FangwenguanwangButton: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(onClickFangwenguanwang), for: .touchUpInside)
        return button
    }()
    private lazy var FangwenguanwangRightImg: UIImageView = {
        let view = UIImageView(image: UIImage(named: "Mine_More"))
        return view
    }()
    private lazy var lineView1: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex6: 0xF1F1F1)
        return view
    }()
    private lazy var lineView2: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex6: 0xF1F1F1)
        return view
    }()
    
    // 用户协议
    private lazy var YonghuxieyiLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "用户协议"
        label.textAlignment = .left
        return label
    }()
    private lazy var YonghuxieyiButton: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(onClickYonghuxieyi), for: .touchUpInside)
        return button
    }()
    private lazy var YonghuxieyiRightImg: UIImageView = {
        let view = UIImageView(image: UIImage(named: "Mine_More"))
        return view
    }()
    private lazy var lineView3: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex6: 0xF1F1F1)
        return view
    }()
    
    // 隐私政策
    private lazy var YinsizhengceLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x404040)
        label.font = Theme.Font.size(16)
        label.text = "隐私政策"
        label.textAlignment = .left
        return label
    }()
    private lazy var YinsizhengceButton: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(onClickYinsizhengce), for: .touchUpInside)
        return button
    }()
    private lazy var YinsizhengceRightImg: UIImageView = {
        let view = UIImageView(image: UIImage(named: "Mine_More"))
        return view
    }()
    private lazy var lineView4: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex6: 0xF1F1F1)
        return view
    }()
   // 底部
    private lazy var BottomLeftImg: UIImageView = {
        let view = UIImageView(image: UIImage(named: "C"))
        return view
    }()
    private lazy var BottomLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hex6:0x999999)
        label.font = Theme.Font.size(16)
        label.text = "2024 Hamaton All rights reserved."
        label.backgroundColor = .clear
        label.textAlignment = .center
        return label
    }()

    // 访问官网
    @objc func onClickFangwenguanwang() {
        // 使用 SFSafariViewController 打开官网页面
        if let url = URL(string: "https://www.hamaton.com.cn/") {
            let safariVC = SFSafariViewController(url: url)
            present(safariVC, animated: true, completion: nil)
        }
    }
    // 用户协议
    @objc func onClickYonghuxieyi() {
        let vc = HamatonAgreementViewController()
        vc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vc, animated: false)
    }
    // 隐私政策
    @objc func onClickYinsizhengce() {
        let vc = HamatonPrivacyViewController()
        vc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vc, animated: false)
    }
}
